import 'package:flutter/cupertino.dart';
import 'package:get/get.dart';
import 'package:get/get_rx/src/rx_types/rx_types.dart';
import 'package:tot_android_flutter/base/BaseController.dart';
import 'package:tot_android_flutter/eneity/user_entity.dart';
import 'package:tot_android_flutter/utils/JsonUtil.dart';
import 'package:tot_android_flutter/utils/log_util.dart';
import 'package:tot_android_flutter/utils/sp/Sp.dart';
import 'package:tot_android_flutter/utils/utils_ext.dart';

import '../../../common/widget/state/view_state.dart';
import '../../../eneity/order_status_entity.dart';

class MineController extends BaseController {
  //浮动导航开关
  RxBool flag = false.obs;
  Rx<UserEntity?> userEntity = Rx(null);
  var orderStatus = <OrderStatusEntity>[].obs;
  var menuList = <OrderStatusEntity>[].obs;
  var otherMenuList = <OrderStatusEntity>[].obs;
  final ScrollController scrollController = ScrollController();

  @override
  void loadData() {
    viewState.value = ViewStateSuccess();
    getUserInfo();
    getOderStatus();
    getMenuList();
    getOtherMenuList();
    WanLog.d("json:${JsonUtils.toJson(userEntity.value)}");
  }

  @override
  void onInit() {
    super.onInit();
    scrollController.addListener(() {
      if (scrollController.offset.toInt() > 20.w) {
        if (flag.value == false) {
          flag.value = true;
        }
      } else {
        if (flag.value == true) {
          flag.value = false;
        }
      }
    });
  }

  void getUserInfo() {
    userEntity.value = Sp.getUserInfo();
  }

  void getOderStatus() {
    var order1 = OrderStatusEntity(title: "全部订单", id: 1, number: 0);
    var order2 = OrderStatusEntity(title: "待收货/使用", id: 2, number: 3);
    var order3 = OrderStatusEntity(title: "待评价", id: 3, number: 0);
    var order4 = OrderStatusEntity(title: "退款售后", id: 4, number: 0);
    var temp = <OrderStatusEntity>[];
    temp.add(order1);
    temp.add(order2);
    temp.add(order3);
    temp.add(order4);
    orderStatus.value = temp;
  }
  void getMenuList() {
    var order1 = OrderStatusEntity(title: "收藏", id: 1, number: 0);
    var order2 = OrderStatusEntity(title: "浏览记录", id: 2, number: 3);
    var order3 = OrderStatusEntity(title: "红包卡券", id: 3, number: 0);
    var order4 = OrderStatusEntity(title: "美团币", id: 4, number: 0);
    var temp = <OrderStatusEntity>[];
    temp.add(order1);
    temp.add(order2);
    temp.add(order3);
    temp.add(order4);
    menuList.value = temp;
  }

  void getOtherMenuList() {
    var order1 = OrderStatusEntity(title: "团团神权", id: 1, number: 0);
    var order2 = OrderStatusEntity(title: "企业服务", id: 2, number: 3);
    var order3 = OrderStatusEntity(title: "开发票", id: 3, number: 0);
    var order4 = OrderStatusEntity(title: "手机充值", id: 4, number: 0);
    var order5 = OrderStatusEntity(title: "入住美团", id: 1, number: 0);
    var order6 = OrderStatusEntity(title: "美团工艺", id: 2, number: 3);
    var order7 = OrderStatusEntity(title: "退现金", id: 3, number: 0);
    var order8 = OrderStatusEntity(title: "全部工具", id: 4, number: 0);
    var temp = <OrderStatusEntity>[];
    temp.add(order1);
    temp.add(order2);
    temp.add(order3);
    temp.add(order4);
    temp.add(order5);
    temp.add(order6);
    temp.add(order7);
    temp.add(order8);
    otherMenuList.value = temp;
  }
}
